/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	GeometryFileWriter.h
*
*	Description -	Utility class for creating an XML-based geometry export file.
*
*	Comments	-	TODO: Make this part of Pulse-Tec Lib once this becomes stable.
*					TODO: The file parsing methods lack thorough error checking. Make
*						sure to work on this later on.
*
*	Modification History:
*			Name			   Date					Description
*			MrCodeSushi	-	09/10/2012	-	Creation of this file
**************************************************************************************/
#ifndef _GEOMETRY_FILE_WRITER_H_
#define _GEOMETRY_FILE_WRITER_H_

#include "../Pulse-Tec/Include/Pulse.h"
#include "Mesh.h"

namespace Pulse
{
	class GeometryFileWriter
	{
	public:

		GeometryFileWriter( void );

		~GeometryFileWriter( void );

		//GeometryFileWriter( const CHAR *pSaveFileName );

		// Create root node
		void StartWrite( const CHAR *pSaveFilename );

		// Save out the entire tree to a file specified in StartWrite
		void EndWrite( void );

		// Vertex Streams
		//////////////////
		SIZE_T32 AddPosition( FLOAT x, FLOAT y, FLOAT z );
		SIZE_T32 AddPosition( Vector3 *pPos );
		
		SIZE_T32 AddNormal( FLOAT x, FLOAT y, FLOAT z );
		SIZE_T32 AddNormal( Vector3 *pNormal );

		// UV Streams - Inside Vertex Streams
		/////////////////
		SIZE_T32 AddTextureDiffuse( FLOAT x, FLOAT y );
		SIZE_T32 AddTextureDiffuse( Vector2 *pUVDiffuse );

		// Index Streams
		/////////////////
		SIZE_T32 AddIndex( UINT index );

		// Sub-Mesh
		SIZE_T32 AddSubGeometry( UPOS_T32 indicesOffset, SIZE_T32 numTriangles );

	private:

		// Set to default values
		void ResetData( void );

		void AddSpace( XMLElement *pElem );

		void PerformLinkEvaluation( void );

	private:

		typedef Array<SubMesh> SubMeshList;

		String m_filename;
		XMLDocument m_doc;
		XMLElementPtr m_pRootNode;
		XMLElementPtr m_pVertexStream;
		XMLElementPtr m_pIndexStream;

		// Geometry info
		XMLElementPtr m_pInfo;
		
		// Vertex Streams
		/////////////////
		SIZE_T32 m_numPositions;
		XMLElementPtr m_pPositions;
		XMLElementPtr m_pPositionsElements;

		SIZE_T32 m_numNormals;
		XMLElementPtr m_pNormals;
		XMLElementPtr m_pNormalsElements;

		// Bi-tangent

		SIZE_T32 m_numTextureDiffuse;
		XMLElementPtr m_pTextureDiffuse;
		XMLElementPtr m_pTextureDiffuseElements;

		// IndexStream
		SIZE_T32 m_numIndices;
		BOOL			m_b16BitIndices;
		XMLElementPtr m_pIndices;
		XMLElementPtr m_pIndicesElements;

		// Sub-Mesh Info
		SIZE_T32		m_numSubMeshes;
		XMLElementPtr	m_pSubGeometry;
		XMLElementPtr	m_pSubGeometryElements;

	};
}

#endif /* _GEOMETRY_FILE_WRITER_H_ */